package co.edu.usbcali.adt.exercises.market.v1;

import java.util.List;

import co.edu.usbcali.adt.utils.ArrayUtil;

public class Main {
	
	public static String[] productCodes={"Milk","Soap","Bread","Egg","Sugar","Rice","Salt","Coffee"};
	public static int[] prices={100,200,50,1,10,50,10,20};
	
	public static void main(String[] args) {
		
		ShoppingCart sc=new ShoppingCart();
		sc.setId(1000);
		sc.addProduct(productCodes[3]);
		sc.addProduct(productCodes[4]);
		sc.addProduct(productCodes[7]);
		sc.addProduct(productCodes[1]);
		sc.addProduct(productCodes[2]);
		sc.addProduct(productCodes[1]);
		sc.setTotal(calculateTotal(sc));
		System.out.println(sc);
	}
	
	/**
	 * Calculates total value of items in a shopping car, it doesn't validate about wrong product codes
	 * @param sc
	 * @return
	 */
	public static long calculateTotal(ShoppingCart sc){
		long total=0;
		List<String> items=sc.getProducts();
		for (String string : items) {
			int pos=ArrayUtil.getPosition(productCodes, string);
			total+=prices[pos];
		}
		return total;
	}

}
